function MsgBox(str) {
	var setting;
	var pre = document.createElement("pre");
	var tem;
	if (typeof str === 'string') {
		setting = {
			title : "提示",
			details : pre
		};
		tem = str;
	} else {
		setting = str;
		tem = setting.details;
	}
	tem = tem.replace(/\n\r/g, '\r').replace(/^\r/, '');
	pre.innerHTML = tem + "<br/>";
	setting.details = pre;
	Dialog.call(this, setting);
	return this;
}
function Dialog(par) {
	var tem = par;
	var bj = document.createElement("div");
	bj.setAttribute("unselectable", "on");
	addEvent(bj, "selectstart", function() {
		return false;
	});
	var m = {
		cm : document.oncontextmenu,
		md : document.onmousedown
	};
	document.oncontextmenu = function(event) {
		return false;
	};
	document.onmousedown = function(event) {
		return false;
	};
	bj.setAttribute("class", "transparent");
	par.parent = undefined;
	par.close = function(c) {
		document.body.removeChild(bj);
		document.oncontextmenu = m.cm;
		document.onmousedown = m.md;
	};
	v = new Window(par);
	document.body.appendChild(bj);
	this.show=function(){
		v.show();
	};
}
function Window(par) {
	var setting = {
		title : "窗口",
		size : {
			width : "400",
		},
		details : "",
		location : {
			top : "0",
			left : "0"
		},
		parent : null,
		close : function(rCode) {
		},
		resize : function(width, height) {
		},
		backgroundColor : '#FFFFFF'
	};
	setting = overrideProperty(setting, par);

	var view = document.createElement("div");
	view.setAttribute("class", "win");
	var details = document.createElement("div");
	details.appendChild(setting.details);
	details.setAttribute("unselectable", "on");
	details.setAttribute("class", "winDetails");
	var buttArea = document.createElement("div");
	buttArea.setAttribute("class", "winButtArea");
	buttArea.setAttribute("style", "top: " + (setting.size.height - 35) + "px;");
	var buttOK = newButt({
		name : "确定",
		event : function() {
			setting.close(1);
			document.body.removeChild(view);
		}
	});
	var buttClose = newButt({
		name : "取消",
		event : function() {
			setting.close(0);
			document.body.removeChild(view);
		}
	});
	buttArea.appendChild(buttOK);
	buttArea.appendChild(buttClose);
	view.appendChild(newTitle(setting.title, view));
	view.appendChild(details);
	view.appendChild(buttArea);
	this.close = function() {
		setting.close(-1);
		document.body.removeChild(view);
	};
	this.show = function() {
		if (par.parent == undefined) {
			document.body.appendChild(view);
		} else {
			par.parent.appendChild(view);
		}
		view.setAttribute("style", "background:" + setting.backgroundColor + ";width:" + setting.size.width + "px;left: "
				+ (document.body.clientWidth - setting.size.width) / 2 + "px;top: " + (document.body.clientHeight - view.offsetHeight) / 2 + "px;");
	}
}
function newButt(par) {
	var butt = document.createElement("div");
	butt.setAttribute("unselectable", "on");
	butt.setAttribute("class", "butt");
	addEvent(butt, "mouseout", function() {
		butt.style.backgroundColor = "#19A1DD";
	});
	addEvent(butt, "mouseover", function() {
		butt.style.backgroundColor = "#35BBF6";
	});
	addEvent(butt, "click", par.event);
	addEvent(butt, "selectstart", function() {
		return false;
	});
	butt.appendChild(document.createTextNode(par.name));
	return butt;
}
function newTitle(title, p) {
	var lable = document.createElement("lable");
	var isDown = false;// 是否能够移动
	var initialLeft = 0; // 鼠标摁下时的坐标
	var initialTop = 0;
	var divLeft = 0; // 鼠标摁下时内部div的坐标
	var divTop = 0;
	lable.appendChild(document.createTextNode(title));
	lable.setAttribute("unselectable", "on");
	lable.setAttribute("class", "winTitel");
	addEvent(lable, "selectstart", function() {
		return false;
	});
	rDrag.init(lable);
	return lable;
}

var rDrag = {
	o : null,
	init : function(o) {
		o.onmousedown = this.start;
	},
	start : function(e) {
		var o;
		e = rDrag.fixEvent(e);
		e.preventDefault && e.preventDefault();
		rDrag.o = o = this.parentElement;
		o.x = e.clientX - rDrag.o.offsetLeft;
		o.y = e.clientY - rDrag.o.offsetTop;
		document.onmousemove = rDrag.move;
		document.onmouseup = rDrag.end;
	},
	move : function(e) {
		e = rDrag.fixEvent(e);
		var oLeft, oTop;
		oLeft = e.clientX - rDrag.o.x;
		oTop = e.clientY - rDrag.o.y;
		rDrag.o.style.left = oLeft + 'px';
		rDrag.o.style.top = oTop + 'px';
	},
	end : function(e) {
		e = rDrag.fixEvent(e);
		rDrag.o = document.onmousemove = document.onmouseup = null;
	},
	fixEvent : function(e) {
		if (!e) {
			e = window.event;
			e.target = e.srcElement;
			e.layerX = e.offsetX;
			e.layerY = e.offsetY;
		}
		return e;
	}
}
